layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    $("#search").click(function(){
        var id=$("#memberId").val();
        if(id==null||id==""){
            top.layer.msg("请输入会员ID");
            return false;
        }
        $.get("/member/JsonSelectEntity",{
            "id":id
        },function(result){
            if(1==result.returnInfo.state){
                $("#nickName").val(result.returnInfo.result.nickName);
                $("#name").val(result.returnInfo.result.name);
                $("#phone").val(result.returnInfo.result.phone);
                $("#headImage").attr("src",result.returnInfo.result.headImage);
            }else{
                top.layer.msg(result.returnInfo.errorMsg);
            }
        })
    });
    form.on("submit(btnSubmit)",function(data){
        var id=$("#memberId").val();
        if(id==null||id==""){
            top.layer.msg("请输入会员ID");
            return false;
        }
        var money=$("#money").val();
        if(money==null||money==""){
            top.layer.msg("请输入充值金额");
            return false;
        }
        layer.confirm('确定向会员ID【'+id+'】充值【'+money+'】个金额吗？',{icon:3, title:'提示信息'},function(index){
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.post("/record/addRecord",{
                "memberId":id,
                "money":money
            },function(result){
                if(1==result.returnInfo.state){
                    top.layer.close(index);
                    top.layer.msg("充值成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    location.reload();
                }else{
                    top.layer.msg(result.returnInfo.errorMsg);
                }
            })
        });
        return false;
    });
})